from llvmlite import ir

from .base import BuiltinFunction, get_builtin_function_cls
from ...types import double, integer


class RandomFloat(BuiltinFunction):
    def register(self):
        func_ty = ir.FunctionType(double, [])
        self.func = ir.Function(self.module, func_ty, name="random_float")


class RandomInteger(BuiltinFunction):
    def register(self):
        func_ty = ir.FunctionType(integer, [integer, integer])
        self.func = ir.Function(self.module, func_ty, name="random_integer")


class Uniform(BuiltinFunction):
    def register(self):
        func_ty = ir.FunctionType(double, [double, double])
        self.func = ir.Function(self.module, func_ty, name="uniform")


class SampleIndex(BuiltinFunction):
    def register(self):
        func_ty = ir.FunctionType(ir.PointerType(integer), [integer, integer])
        self.func = ir.Function(self.module, func_ty, name="sample_index")


builtin_random_funcs = get_builtin_function_cls(globals())
